﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using TianYa.Data;
using Microsoft.Phone.Data.Linq;

namespace TianYa
{
    public class TianYaApplicationService : IApplicationService
    {
        private const int dbVersion = 2;
        public void StartService(ApplicationServiceContext context)
        {
            G.Net.Oauth.OauthConfiger.AppKey = "e47df51d3c63b4bf2e57a9e4209d1c5d04fb1bf57";
            G.Net.Oauth.OauthConfiger.AppSecret = "5dc56774960672ae03ffa7ce246d9320";
            G.Net.Oauth.OauthConfiger.AccessToken = G.Net.Oauth.OAuthAccessToken.Load("tianya_token");
            #region 添加有Tile效果的类型
            TiltEffect.TiltableItems.Add(typeof(ListBoxItem));
            TiltEffect.TiltableItems.Add(typeof(System.Windows.Controls.Primitives.ButtonBase));
            TiltEffect.TiltableItems.Add(typeof(G.Controls.TileControl));
            #endregion



            using (TianYaDataBase db = new TianYaDataBase())
            {
                DatabaseSchemaUpdater dbUpdate = db.CreateDatabaseSchemaUpdater();
                if (!db.DatabaseExists())
                {
                    db.CreateDatabase();
                    dbUpdate.DatabaseSchemaVersion = 2;
                    dbUpdate.Execute();
                }
                if (dbUpdate.DatabaseSchemaVersion < 2)
                {
                    dbUpdate.AddTable<Data.FavoritPlate>();
                    dbUpdate.DatabaseSchemaVersion = 2;
                    dbUpdate.Execute();
                }
            }

        }

        public void StopService()
        {

        }
    }
}
